
<?php
	require_once("connect_sql.php");
	
	$type = $_GET['type'];
	$ret = "false";

	//echo $type.'-';
	//print_r($dataArray);
	
	if($type == "platform") {
		$sql = sprintf('select id from %s where name="%s"', $type, $_GET['name']);
		$result = mysql_query($sql);
		if(!$result) echo mysql_error();
		if(mysql_num_rows($result) > 0) {
			$ret = "exist,".$type;
		} else {
			$sql = sprintf('insert into %s (name, code, downloadTool) values("%s", "%s", "%s")', $type, $_GET['name'], $_GET['code'], $_GET['downloadTool']);
			//echo $sql;
			if(!mysql_query($sql)) {
				$ret = "";
			} else {
				$ret = "successed,".$type;
				
				$str = '新平台('.$_GET['name'].', '.$_GET['code'].', '.$_GET['downloadTool'].')';
				mysql_query('insert into log (user, nickname, action, date, content, sqlStr) values("'.$_COOKIE['username'].'", "'.$_COOKIE['nickname'].'", "添加", "'.date("Y-m-d").'", \''.$str.'\', \''.$sql.'\')');
			}
		}
	} else if($type == "camera" || $type == 'lcd') {
		$nameArray = $_GET['name'];
		$sizeArray = $_GET['size'];
		while(list($key, $val) = each($nameArray)) {
			$sql = sprintf('select id from %s where name="%s"', $type, $val);
			$result = mysql_query($sql);
			if(!$result) echo mysql_error();
			if(mysql_num_rows($result) > 0) {
				$ret = 'exist,'.$type;
				break;
			} else {
				$sql = sprintf('insert into %s (name, size) values("%s", "%s")', $type, $val, $sizeArray[$key]);
				if(!mysql_query($sql)) {
					$ret = "";
				} else {
					$ret = "successed,".$type;
					
					if($type == 'camera') $str = '新摄像头';
					else $str = '新屏';
					$str .= '('.$val.', '.$sizeArray[$key].')';
					mysql_query('insert into log (user, nickname, action, date, content, sqlStr) values("'.$_COOKIE['username'].'", "'.$_COOKIE['nickname'].'", "添加", "'.date("Y-m-d").'", \''.$str.'\', \''.$sql.'\')');
				}
			}
		}
	} else if($type == 'customer') {
		$data = $_GET['data'];
		for($i = 0; $i < count($data); ) {
			$sql = sprintf('select id from %s where name="%s"', $type, $data[$i]);
			$result = mysql_query($sql);
			if(!$result) echo mysql_error();
			if(mysql_num_rows($result) > 0) {
				$ret = "exist,".$type;
				break;
			} else {
				$sql = sprintf('insert into %s (name, abbreviate) values("%s", "%s")', $type, $data[$i], $data[$i+1]);
				if(!mysql_query($sql)) {
					$ret = "";
				} else {
					$ret = "successed,".$type;
					
					$str = '新客户('.$data[$i++].', '.$data[$i++].')';
					mysql_query('insert into log (user, nickname, action, date, content, sqlStr) values("'.$_COOKIE['username'].'", "'.$_COOKIE['nickname'].'", "添加", "'.date("Y-m-d").'", \''.$str.'\', \''.$sql.'\')');
				}
			}
		}
	} else {
		$dataArray = $_GET['data'];
		while(list($key, $val) = each($dataArray)) {
			$sql = sprintf('select id from %s where name="%s"', $type, $val);
			$result = mysql_query($sql);
			if(!$result) echo mysql_error();
			if(mysql_num_rows($result) > 0) {
				$ret = "exist,".$type;
				break;
			} else {
				$sql = sprintf('insert into %s (name) values("%s")', $type, $val);
				//echo $sql.'-';
				if(!mysql_query($sql)) {
					$ret = "";
				} else {
					$ret = "successed,".$type;
					
					if($type == 'author') $str = '新项目负责人';
					else if($type == 'rfpa') $str = '新射频PA';
					else if($type == 'classK') $str = '新功放';
					else if($type == 'function') $str = '新软件功能';
					$str .= '('.$val.')';
					mysql_query('insert into log (user, nickname, action, date, content, sqlStr) values("'.$_COOKIE['username'].'", "'.$_COOKIE['nickname'].'", "添加", "'.date("Y-m-d").'", \''.$str.'\', \''.$sql.'\')');
				}
			}
		}
	}
	echo $ret;
?>